package ru.hh.team02.chat.server;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;


public class MessageSender {
    private static final BlockingQueue<Message> messageQueue = 
            new LinkedBlockingQueue<Message>();
    
    MessageSender() {
        Thread t = new Thread() {
            public void run () {
                while (true) {
                    sendMessage();
                }
            }
        };
        
        t.start();
    }
    
    void addMessage(final Message message) {
        messageQueue.add(message);
    }

    void sendMessage() {
        Message message = null;
        try {
            message = messageQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } 
        message.out.println(message.message);
    }
}
